import {getDangerExport} from "@/api/safety";
import {getConstExport} from "@/api/project";
import {initYMD} from "@/sever/utils";


export const exportObj = {
    data() {
        return {
            exportDeptId: '',//导出组织机构ID
            exportModal: false,//导出弹框
            exportIndex: 1,//导出模块下标
        }
    },
    methods: {
        commandFn(type){
            this.$router.push({path:'/exp/list'})
        },
        //导出弹框显示
        exportFn(active) {
            this.exportIndex = active;
            let params = {};
            let getExport = null;
            if (this.exportIndex == 1) {
                params = {
                    deptId: this.exportDeptId,
                }
                getExport = getDangerExport;
            }else if(this.exportIndex == 2){
                params = {
                    deptId: this.exportDeptId,
                    time:initYMD(this.day)
                }
                getExport = getConstExport;

            }
            this.getExport(JSON.stringify(params),getExport)
        },
        //接受子组件传递过来的数据
        handleClose(e) {
            this.exportModal = e;
        },
        //数据提交
        getExport(params, getExport) {
            params = JSON.parse(params);
            getExport(params).then(res => {
                if (res.code == 200) {
                    this.exportModal = true;
                } else {
                    this.$Message.warning(res.msg);
                }
            })
            .catch(error => console.log(error))
        }
    },
    mounted() {
        this.exportDeptId = this.$store.state.porjectObject.deptId;
    },
    computed: {
        porjectObject() {
            return this.$store.state.porjectObject;
        }
    },
    watch: {
        porjectObject(val, oldVal) {
            if (val.deptId != oldVal.deptId) {
                this.exportDeptId = val.deptId;
            }
        },
    },
}
